package com.nononsenseapps.feeder.pad.ui.reader.webview

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.add
import androidx.fragment.app.commit
import com.nononsenseapps.feeder.ui.reader.sample.ARG_ENCLOSURE
import com.nononsenseapps.feeder.ui.reader.webview.ARG_URL
import com.nononsenseapps.feeder.ui.reader.webview.ReaderWebViewFragment

class ReaderWebFragmentDialog : DialogFragment() {

    private val CONTAINER_ID: Int = 0x2223
    private val TAG:String="read_web_fragment"

    var url: String = ""
    private var enclosureUrl: String? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let { arguments ->
            url = arguments.getString(ARG_URL, null) ?: ""
            enclosureUrl = arguments.getString(ARG_ENCLOSURE, null)
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val wrapper = FrameLayout(activity)
        wrapper.id = CONTAINER_ID
        childFragmentManager.commit {
            add<ReaderWebViewFragment>(CONTAINER_ID,TAG, Bundle().apply{
                putString(ARG_URL,url)
                enclosureUrl?.let{
                    putString(ARG_ENCLOSURE,it)
                }
            })
        }
        return wrapper
    }
}